#include "Coin.h"

#include "HeroClass.h"
#include "Level.h"

Coin::Coin(const Vector2df p, const Vector2df v) : StatefulUnit(p,v)
{
    loadSprite("Coin.sprite");
    setSpriteState("Spinning");
};

Coin::~Coin()
{
    //dtor
}

void Coin::hit(const SimpleDirection dir, BaseUnit* player, CRstring parameter) {
    player->hit(diNONE,this);
    handleEvent("Hit");
}

bool Coin::processEvent(vector<string> event)
{
    if (not StatefulUnit::processEvent(event))
    {
        if (event.size() > 1)
        {
            if (event[0] == "Hero")
            {
                if (event[1] == "AddCoins")
                {
                    Hero *hero = (Hero *)getLevel()->GetHero();
                    if (event.size()>2)
                        hero->addCoins(atoi(event[2].c_str()));
                    else
                        hero->addCoins(1);
                    return true;
                }
            }
        }
        return false;
    }
    return true;
}
